#include <bits/stdc++.h>
using namespace std;
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x = x * f;
    return x;
}
void write(int x)
{
    if (x < 0)
    {
        x = -x;
        putchar('-');
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
int t;
int n, m, L, V;
int st[100005], vst[100005], a[100005];
int ck[100005];
int mst[100005];
int ans1 = 0, ans2 = 0;
int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    t = read();
    while (t--)
    {
        n = read(), m = read(), L = read(), V = read();
        bool fa = 1, fb = 1;
        for (int i = 1; i <= n; i++)
        {
            st[i] = read(), vst[i] = read(), a[i] = read();
            if (a[i] != 0)
            {
                fa = 0;
            }
            if (a[i] <= 0)
            {
                fb = 0;
            }
        }
        if (fa == 1)
        {
            for (int i = 1; i <= m; i++)
            {
                ck[i] = read();
            }
            for (int i = 1; i <= n; i++)
            {
                if (vst[i] <= V && a[i] == 0)
                    continue;
                if (a[i] == 0 && vst[i] > V)
                {
                    if (st[i] > ck[m])
                        continue;
                    else
                        ans1++;
                }
            }
            if (ans1 != 0)
            {
                write(ans1);
                putchar(' ');
                write(m - 1);
                printf("\n");
                ans1 = 0;
            }
            else
            {
                write(ans1);
                putchar(' ');
                write(m);
                printf("\n");
                ans1 = 0;
            }
        }
        else if (fb == 1)
        {
            for (int i = 1; i <= m; i++)
            {
                ck[i] = read();
            }
            for (int i = 1; i <= n; i++)
            {
                if (st[i] > ck[m])
                    continue;
                if (vst[i] <= V && a[i] == 0)
                    continue;
                if (a[i] == 0 && vst[i] > V)
                {
                    bool f = 0;
                    for (int j = 1; j <= m; j++)
                    {
                        if (st[i] <= ck[j])
                        {
                            mst[m]++;
                            f = 1;
                            break;
                        }
                    }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] == V && a[i] > 0)
                {
                    bool f = 0;
                    int j=m;
                        if (st[i] <= ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                mst[m]++;
                            }
                        }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] > V && a[i] > 0)
                {
                    bool f = 0;
                    int j=m;
                        if (st[i] <= ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                mst[m]++;
                            }
                        }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] < V && a[i] > 0)
                {
                    bool f = 0;
                        int j=m;
                        if (st[i] <= ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                mst[m]++;
                            }
                        }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] < V && a[i] < 0)
                    continue;
                if (vst[i] == V && a[i] < 0)
                    continue;
                if (vst[i] > V && a[i] < 0)
                {
                    bool f = 0;
                    for (int j = 1; j <= m; j++)
                    {
                        int k;
                        if (st[i] < ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            if (double(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0) < 0)
                            {
                                mst[k]++;
                                break;
                            }
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                k = j;
                            }
                        }
                    }
                    if (f == 1)
                        ans1++;
                    continue;
                }
            }
            write(ans1);
            putchar(' ');
            int ans2 = 0;
            ans1 = 0;
            for (int i = 1; i <= m; i++)
            {
                if (mst[i] != 0)
                    ans2++;
            }
            write(m - ans2);
            printf("\n");
            memset(mst, 0, sizeof(mst));
        }else{
            for (int i = 1; i <= m; i++)
            {
                ck[i] = read();
            }
            for (int i = 1; i <= n; i++)
            {
                if (st[i] > ck[m])
                    continue;
                if (vst[i] <= V && a[i] == 0)
                    continue;
                if (a[i] == 0 && vst[i] > V)
                {
                    bool f = 0;
                    for (int j = 1; j <= m; j++)
                    {
                        if (st[i] <= ck[j])
                        {
                            mst[m]++;
                            f = 1;
                            break;
                        }
                    }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] == V && a[i] > 0)
                {
                    bool f = 0;
                    int j=m;
                        if (st[i] <= ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                mst[m]++;
                            }
                        }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] > V && a[i] > 0)
                {
                    bool f = 0;
                    int j=m;
                        if (st[i] <= ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                mst[m]++;
                            }
                        }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] < V && a[i] > 0)
                {
                    bool f = 0;
                        int j=m;
                        if (st[i] <= ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                mst[m]++;
                            }
                        }
                    if (f == 1)
                        ans1++;
                    continue;
                }
                if (vst[i] < V && a[i] < 0)
                    continue;
                if (vst[i] == V && a[i] < 0)
                    continue;
                if (vst[i] > V && a[i] < 0)
                {
                    bool f = 0;
                    for (int j = 1; j <= m; j++)
                    {
                        int k;
                        if (st[i] < ck[j])
                        {
                            double dis = (ck[j] - st[i]) * 1.0;
                            if (double(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0) < 0)
                            {
                                mst[k]++;
                                break;
                            }
                            double vnow = sqrt(vst[i] * vst[i] * 1.0 + 2 * a[i] * dis * 1.0);
                            if (vnow > double(V))
                            {
                                f = 1;
                                k = j;
                            }
                        }
                    }
                    if (f == 1)
                        ans1++;
                    continue;
                }
            }
            write(ans1);
            putchar(' ');
            int ans2 = 0;
            ans1 = 0;
            for (int i = 1; i <= m; i++)
            {
                if (mst[i] != 0)
                    ans2++;
            }
            write(m - ans2);
            printf("\n");
            memset(mst, 0, sizeof(mst));
        }
    }
    return 0;
}